*************************************************************************
** 							GENDER AND WEALTH						   **
**					Doron Shiffer-Sebba and Julia Behrman 			   **
**						Last updated: 10/19/2020, DSS				   **
*************************************************************************


***************************************************************************
*** SETUP *****************************************************************
***************************************************************************	 

version 14.2
clear
capture log close
set more off

global path    "/localpath"   /* Adjust to user project folder path */

log 		using ""$path/output/4", replace
use 		"$path/data/final", clear
global		indvars    "permarriedhh percenthisp perblack persomecollege perover100k prop_size sale_year currentpropertyvalue purchasedprice"	

***************************************************************************
*** CONTENTS **************************************************************
***************************************************************************

/*
- Table 1. City Specific Variable Means by Ownership Type and Philadelphia
- Appendix Table: IVs by City by different measures of ownership, post-2016 only
- Robustness Check: 98%	
- Robustness check - No Name Cut-Off
*/

******************************************************************************
*** Table 1. City Specific Variable Means by Ownership Type and Philadelphia
******************************************************************************

asdoc, row(\i,\i,\i, Mutually Exclusive Measure,\i,\i,\i,\i, Non-Exclusive Measure,\i) ///
	save($path/wrdfiles/combined_ivshmstd) replace title(Table 1. City Specific Variable Mean Comparison by Ownership Type)
asdoc, row(\i,Male Solo,\i,Female Solo,\i,Pair,\i,Other,Has Male,Has Female) save($path/wrdfiles/combined_ivshmstd) append
forvalues city = 1/2	{
	local f`city': label city3 `city' 
	asdoc, row(\i,\i,\i,\i,\i,`f`city'',\i,\i,\i,\i) save($path/wrdfiles/combined_ivshmstd) fs(12) append
	foreach x in $indvars {
		local y: variable label `x'
		ttest `x' if city3 == `city' & sample == 1 & hmstd == 1, by(malefemale)
		if `r(p)' < 0.05	{
			asdoc, accum(`r(mu_2)',*,`r(mu_1)')
			}
		else				{
			asdoc, accum(`r(mu_2)',\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & sample == 1 & hmstd == 1, by(femalesolomixed)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & sample == 1 & hmstd == 1, by(mixedother)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		sum `x' if city3 == `city' & sample == 1 & hmstd == 1 & hasmale == 1
		asdoc, accum(`r(mean)')
		sum `x' if city3 == `city' & sample == 1 & hmstd == 1 & hasfemale == 1
		asdoc, accum(`r(mean)')
		asdoc, row(`y', $accum) save($path/wrdfiles/combined_ivshmstd) append
		}
		tab ownertype if city3 == `city' & sample == 1 & hmstd == 1, matcell(freqs)
		local male = freqs[1,1]
		local female = freqs[2,1]
		local mixed = freqs[3,1]
		local other = freqs[4,1]
		asdoc, accum(`male',\i,`female',\i,`mixed',\i,`other')
		tab hasmale if city3 == `city' & sample == 1 & hmstd == 1, matcell(freqs1)
		local hasmale = freqs1[2,1]
		asdoc, accum(`hasmale')
		tab hasfemale if city3 == `city' & sample == 1 & hmstd == 1, matcell(freqs2)
		local hasfemale = freqs2[2,1]
		asdoc, accum(`hasfemale')
		asdoc, row(N, $accum) save($path/wrdfiles/combined_ivshmstd) append
	}
asdoc, text(Note: * denotes t-test significance at 95% for values on either side; Has Male and Has Female were not compared using t-tests because they are not mutually exclusive categories.) ///
	fs(8) save($path/wrdfiles/combined_ivshmstd) append


************************************************************************************
** Appendix Table: IVs by City by different measures of ownership, post-2016 only
************************************************************************************

asdoc, row(\i,\i,\i, Mutually Exclusive Measure,\i,\i,\i,\i, Non-Exclusive Measure,\i) ///
	save($path/wrdfiles/combined_ivs2016hmstd) replace title(Appendix 1. City Specific Variable Mean Comparison by Ownership Type, Purchases after 2016)
asdoc, row(\i,Male Solo,\i,Female Solo,\i,Pair,\i,Other,Has Male,Has Female) save($path/wrdfiles/combined_ivs2016hmstd) append
forvalues city = 1/2	{
	local f`city': label city3 `city' 
	asdoc, row(\i,\i,\i,\i,\i,`f`city'',\i,\i,\i,\i) save($path/wrdfiles/combined_ivs2016hmstd) fs(12) append
	foreach x in $indvars {
		local y: variable label `x'
		ttest `x' if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, by(malefemale)
		if `r(p)' < 0.05	{
			asdoc, accum(`r(mu_2)',*,`r(mu_1)')
			}
		else				{
			asdoc, accum(`r(mu_2)',\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, by(femalesolomixed)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, by(mixedother)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		sum `x' if city3 == `city' & sample == 1 & post2016 == 1 & hasmale == 1 & hmstd == 1
		asdoc, accum(`r(mean)')
		sum `x' if city3 == `city' & sample == 1 & post2016 == 1 & hasfemale == 1 & hmstd == 1
		asdoc, accum(`r(mean)')
		asdoc, row(`y', $accum) save($path/wrdfiles/combined_ivs2016hmstd) append
		}
		tab ownertype if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, matcell(freqs)
		local male = freqs[1,1]
		local female = freqs[2,1]
		local mixed = freqs[3,1]
		local other = freqs[4,1]
		asdoc, accum(`male',\i,`female',\i,`mixed',\i,`other')
		tab hasmale if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, matcell(freqs1)
		local hasmale = freqs1[2,1]
		asdoc, accum(`hasmale')
		tab hasfemale if city3 == `city' & sample == 1 & post2016 == 1 & hmstd == 1, matcell(freqs2)
		local hasfemale = freqs2[2,1]
		asdoc, accum(`hasfemale')
		asdoc, row(N, $accum) save($path/wrdfiles/combined_ivs2016hmstd) append
	}
asdoc, text(Note: * denotes t-test significance at 95% for values on either side; Has Male and Has Female were not compared using t-tests because they are not mutually exclusive categories.) ///
	fs(8) save($path/wrdfiles/combined_ivs2016hmstd) append


***************************
** Robustness check - 98%
***************************

set more off
asdoc, row(\i,\i,\i, Mutually Exclusive Measure,\i,\i,\i,\i, Non-Exclusive Measure,\i) ///
	save($path/wrdfiles/combined_ivshmstd98) replace title(Table 1. City Specific Variable Mean Comparison by Ownership Type with 98% Gender Confidence)
asdoc, row(\i,Male Solo,\i,Pair,\i,Female Solo,\i,Other,Has Male,Has Female) save($path/wrdfiles/combined_ivshmstd98) append
forvalues city = 1/2	{
	local f`city': label city3 `city' 
	asdoc, row(\i,\i,\i,\i,\i,`f`city'',\i,\i,\i,\i) save($path/wrdfiles/combined_ivshmstd98) fs(12) append
	foreach x in $indvars {
		local y: variable label `x'
		ttest `x' if city3 == `city' & sample2 == 1 & hmstd == 1, by(malesolomixed)
		if `r(p)' < 0.01	{
			asdoc, accum(`r(mu_2)',*,`r(mu_1)')
			}
		else				{
			asdoc, accum(`r(mu_2)',\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & sample2 == 1 & hmstd == 1, by(femalesolomixed)
		if `r(p)' < 0.01	{
			asdoc, accum(*,`r(mu_2)')
			}
		else				{
			asdoc, accum(\i,`r(mu_2)')
			}
		ttest `x' if city3 == `city' & sample2 == 1 & hmstd == 1, by(otherfemale)
		if `r(p)' < 0.01	{
			asdoc, accum(*,`r(mu_2)')
			}
		else				{
			asdoc, accum(\i,`r(mu_2)')
			}
		sum `x' if city3 == `city' & sample2 == 1 & hmstd == 1 & hasmale == 1
		asdoc, accum(`r(mean)')
		sum `x' if city3 == `city' & sample2 == 1 & hmstd == 1 & hasfemale == 1
		asdoc, accum(`r(mean)')
		asdoc, row(`y', $accum) save($path/wrdfiles/combined_ivshmstd98) append
		}
		tab ownertype if city3 == `city' & sample2 == 1 & hmstd == 1, matcell(freqs)
		local male = freqs[1,1]
		local female = freqs[2,1]
		local mixed = freqs[3,1]
		local other = freqs[4,1]
		asdoc, accum(`male',\i,`mixed',\i,`female',\i,`other')
		tab hasmale if city3 == `city' & sample2 == 1 & hmstd == 1, matcell(freqs1)
		local hasmale = freqs1[2,1]
		asdoc, accum(`hasmale')
		tab hasfemale if city3 == `city' & sample2 == 1 & hmstd == 1, matcell(freqs2)
		local hasfemale = freqs2[2,1]
		asdoc, accum(`hasfemale')
		asdoc, row(N, $accum) save($path/wrdfiles/combined_ivshmstd98) append
	}
asdoc, text(Note: * denotes t-test significance at 99% for values on either side; Has Male and Has Female were not compared using t-tests because they are not mutually exclusive categories.) ///
	fs(8) save($path/wrdfiles/combined_ivshmstd98) append

	
**************************************
** Robustness check - No Name Cut-Off
**************************************

set more off
asdoc, row(\i,\i,\i, Mutually Exclusive Measure,\i,\i,\i,\i, Non-Exclusive Measure,\i) ///
	save($path/wrdfiles/combined_ivshmstd_rob) replace title(Appendix Table 4. City Specific Variable Mean Comparison by Ownership Type with No Name Confidence Cut-Off)
asdoc, row(\i,Male Solo,\i,Female Solo,\i,Pair,\i,Other,Has Male,Has Female) save($path/wrdfiles/combined_ivshmstd_rob) append
forvalues city = 1/2	{
	local f`city': label city3 `city' 
	asdoc, row(\i,\i,\i,\i,\i,`f`city'',\i,\i,\i,\i) save($path/wrdfiles/combined_ivshmstd_rob) fs(12) append
	foreach x in $indvars {
		local y: variable label `x'
		ttest `x' if city3 == `city' & hasnoacs != 1 & hmstd == 1, by(malefemale)
		if `r(p)' < 0.05	{
			asdoc, accum(`r(mu_2)',*,`r(mu_1)')
			}
		else				{
			asdoc, accum(`r(mu_2)',\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & hasnoacs != 1 & hmstd == 1, by(femalesolomixed)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		ttest `x' if city3 == `city' & hasnoacs != 1 & hmstd == 1, by(mixedother)
		if `r(p)' < 0.05	{
			asdoc, accum(*,`r(mu_1)')
			}
		else				{
			asdoc, accum(\i,`r(mu_1)')
			}
		sum `x' if city3 == `city' & hasnoacs != 1 & hmstd == 1 & hasmale == 1
		asdoc, accum(`r(mean)')
		sum `x' if city3 == `city' & hasnoacs != 1 & hmstd == 1 & hasfemale == 1
		asdoc, accum(`r(mean)')
		asdoc, row(`y', $accum) save($path/wrdfiles/combined_ivshmstd_rob) append
		}
		tab ownertype if city3 == `city' & hasnoacs != 1 & hmstd == 1, matcell(freqs)
		local male = freqs[1,1]
		local female = freqs[2,1]
		local mixed = freqs[3,1]
		local other = freqs[4,1]
		asdoc, accum(`male',\i,`female',\i,`mixed',\i,`other')
		tab hasmale if city3 == `city' & hasnoacs != 1 & hmstd == 1, matcell(freqs1)
		local hasmale = freqs1[2,1]
		asdoc, accum(`hasmale')
		tab hasfemale if city3 == `city' & hasnoacs != 1 & hmstd == 1, matcell(freqs2)
		local hasfemale = freqs2[2,1]
		asdoc, accum(`hasfemale')
		asdoc, row(N, $accum) save($path/wrdfiles/combined_ivshmstd_rob) append
	}
asdoc, text(Note: * denotes t-test significance at 95% for values on either side; Has Male and Has Female were not compared using t-tests because they are not mutually exclusive categories.) ///
	fs(8) save($path/wrdfiles/combined_ivshmstd_rob) append

	
clear
capture log close
exit


